<{include file="Public/top.html"}>
</head>
<body>
<div id="warpper">
    <div class="content">
        <div class="location">签到</div>
        <div class="ui-tab">
            <{include file="Sign/setNav.html"}>
        </div>
        <div class="SignInBOx">
            <form action="" class="ui-form" id="submitForm">
                <div class="ui-form-item">
                    <h3 class="inline-block SignIn">当月满签奖励</h3>
                    <div class="inline-block">
                        <input type="button" class="<{if $switch[0] == 1}>switches2<{else}>switches1<{/if}>" value="<{if $switch[0] == 1}>启用<{else}>停用<{/if}>" id="fullMonthSwitch">
                        <input type="hidden" value="<{if $switch[0] == 1}>1<{else}>0<{/if}>" name="fullSignSwitch" id="fullSignSwitch">
                    </div>
                </div>
                <div class="ui-form-item">
                    <h3 class="inline-block SignIn">每日签到加 <input type="text" class="ui-text" name="rewardTimes" id="rewardTimes" style="width:15px;" <{if $switch[1] == 0}>disabled value="" <{else}>value="<{$switch[2]}>"<{/if}>/> 次</h3>
                    <div class="inline-block">
                        <input type="button" class="<{if $switch[1] == 1}>switches2<{else}>switches1<{/if}>" value="<{if $switch[1] == 1}>启用<{else}>停用<{/if}>" id="specialSwitch">
                        <input type="hidden" value="<{if $switch[1] == 1}>1<{else}>0<{/if}>" name="specialTimeSwitch" id="specialTimeSwitch">
                    </div>
                </div>
                <div class="ui-form-item">
                    <h3 class="inline-block">时间段</h3>
                    <input type="text" name="startDate" id="startDate" class="ui-select startDate" style="width:95px;" <{if $switch[1] == 0}> value="" disabled <{else}> value="<{$switch[3]|date_format:'%Y-%m-%d'}>"<{/if}>/>
                    <label>—</label>
                    <input type="text" name="endDate" id="endDate" class="ui-select endDate" style="width:95px;" <{if $switch[1] == 0}>disabled value="" <{else}>value="<{$switch[4]|date_format:'%Y-%m-%d'}>"<{/if}>/>
                </div>
                <div class="ui-form-item inline-block" style="margin-top: 20px;margin-left: 30%;">
                    <button type="button" class="ui-button" onclick="saveData()">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
<{include file="Public/foot.html" }>
<script>
    window.onload = function(){
        $(".switches1,.switches2").click(function(){
            if($(this).hasClass("switches1")){
                $(this).removeClass("switches1");
                $(this).addClass("switches2");
            }
            else if($(this).hasClass("switches2")){
                $(this).removeClass("switches2");
                $(this).addClass("switches1");
            }
            $(this).val($(this).val() == "停用"?"启用":"停用");
            if($(this).attr("id") == "fullMonthSwitch"){
                $("#fullSignSwitch").val($("#fullSignSwitch").val() == 0?1:0);
            } else if($(this).attr("id") == "specialSwitch"){
                if($("#specialTimeSwitch").val() == 0){
                    $("#specialTimeSwitch").val(1);
                    $("#rewardTimes,#startDate,#endDate").removeAttr("disabled");
                } else {
                    $("#specialTimeSwitch").val(0);
                    $("#rewardTimes,#startDate,#endDate").val('').attr("disabled",true);
                }
            }
        })
    }

    function saveData() {
        var param = $("#submitForm").serialize();
        var url = "<{U('Sign/saveSwitch')}>";
        var specialTimeSwitch = $("#specialTimeSwitch").val();
        var rewardTimes = $("#rewardTimes").val();
        var startDate = $("#startDate").val();
        var endDate = $("#endDate").val();

        if(specialTimeSwitch == 1 &&(rewardTimes <=0 || !startDate || !endDate)){
            layer.msg("请输入完整信息");
            return false;
        }
        $.get(url,param,function(res){
            layer.msg(res.msg);
            if(res.status == 0){
                window.location.reload();
            }

        });
    }
    datePickter('startDate','endDate',1);
</script>
</body>
</html>
